package org.dromara.system.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.core.utils.file.MimeTypeUtils;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.domain.vo.AvatarVo;
import org.dromara.system.domain.vo.SysOssVo;
import org.dromara.system.service.ISysOssService;
import org.dromara.system.service.ISysUserService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.WbPowerCircleVo;
import org.dromara.system.domain.bo.WbPowerCircleBo;
import org.dromara.system.service.IWbPowerCircleService;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 电力圈增删改查
 *
 * @author Lion Li
 * @date 2024-05-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/powerCircle")
public class WbPowerCircleController extends BaseController {

    private final IWbPowerCircleService wbPowerCircleService;
    private final ISysUserService userService;
    private final ISysOssService ossService;

    /**
     * 查询电力圈列表
     */
    @SaCheckPermission("system:powerCircle:list")
    @GetMapping("/list")
    public TableDataInfo<WbPowerCircleVo> list(WbPowerCircleBo bo, PageQuery pageQuery) {
        return wbPowerCircleService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出电力圈列表
     */
    @SaCheckPermission("system:powerCircle:export")
    @Log(title = "电力圈增删改查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WbPowerCircleBo bo, HttpServletResponse response) {
        List<WbPowerCircleVo> list = wbPowerCircleService.queryList(bo);
        ExcelUtil.exportExcel(list, "电力圈增删改查", WbPowerCircleVo.class, response);
    }

    /**
     * 获取电力圈详细信息
     *
     * @param circleId 主键
     */
    @SaCheckPermission("system:powerCircle:query")
    @GetMapping("/{circleId}")
    public R<WbPowerCircleVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long circleId) {
        return R.ok(wbPowerCircleService.queryById(circleId));
    }

    /**
     * 新增电力圈
     */
    @SaCheckPermission("system:powerCircle:add")
    @Log(title = "电力圈文章", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WbPowerCircleBo bo ) {

        return toAjax(wbPowerCircleService.insertByBo(bo));
    }

    /**
     * 修改电力圈文章
     */
    @SaCheckPermission("system:powerCircle:edit")
    @Log(title = "电力圈文章修改", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WbPowerCircleBo bo) {
        return toAjax(wbPowerCircleService.updateByBo(bo));
    }

    /**
     * 删除电力圈
     *
     * @param circleIds 主键串
     */
    @SaCheckPermission("system:powerCircle:remove")
    @Log(title = "电力圈增删改查", businessType = BusinessType.DELETE)
    @DeleteMapping("/{circleIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] circleIds) {
        return toAjax(wbPowerCircleService.deleteWithValidByIds(List.of(circleIds), true));
    }
}
